class Player {
    constructor(playerData, client) {
        //{user_id: 666666, user_name: "金财主", user_head_url: "www.baidu.com", user_room_cards: 10000, room_id: null}
        this.userID = playerData.user_id;
        this.userName = playerData.user_name;
        this.userHeadUrl = playerData.user_head_url;
        this.userRoomCards = playerData.user_room_cards;
        this.roomID = undefined;
        this.room = undefined;
        this.client = client;
        this.seatIndex = undefined;
        this.readyState = false;
        this.is_open = false;
        this.is_fold = false;
        this.cards = [];
        this.current_score = 0;
        this.receviedPlayerMessage(this.client);
    }

    getPlayerInfo() {
        return {
            user_id: this.userID,
            user_name: this.userName,
            user_head_url: this.userHeadUrl,
            user_seatIndex: this.seatIndex,
            //炸金花游戏状态
            //是否明牌
            is_open: this.is_open,
            //是否弃牌
            is_fold: this.is_fold,
            //当前分数
            current_score: this.current_score,
            //当前有牌权的玩家
            current_player_id: this.room.current_player_id,
            //当前房间下注总分数
            total_bet: this.room.total_bet,
        }
    }

    getPlayerReadyState() {
        return {
            user_id: this.userID,
            user_seatIndex: this.seatIndex,
            ready_state: this.readyState,
        }
    }
    receviedPlayerMessage(client) {
        client.on("text", (result) => {
            let message = JSON.parse(result);
            let type = message.type;
            let data = message.data;
            console.log('游戏服务器玩家实例对象接收到消息；消息类型->', type, '，数据为->', data);

            switch (type) {
                case 'ready_ok':
                    this.room.StartGameOrSyncReadyMessage(this);
                    break;

                default:
                    break;
            }
        })
    }
}

module.exports = Player;